package leetcode.weekly.week327;

import java.util.PriorityQueue;

//Solution2Test
public class Solution2 {

	public long maxKelements(int[] nums, int k) {
		PriorityQueue<Integer> queue = new PriorityQueue<>((a, b) -> b - a);
		for (int num : nums) {
			queue.add(num);
		}
		long ans = 0;
		while (k > 0) {
			int cur = queue.poll();
			ans += 1l * cur;
			long next = (1l * cur + 2) / 3;
			queue.add((int) next);
			k--;
		}
		return ans;
	}

}
